#ifndef __LR_COMMANDPARSER_HEADER__
#define __LR_COMMANDPARSER_HEADER__
//##############################################################################




/** Command description */
typedef struct
{
  // Pointer to the command word
  signed char * word;
  // ID of the command
  unsigned int id : 31;
  // Current state of the command (1 = still possible)
  unsigned int state : 1;
} LR_commandparser_command;
//------------------------------------------------------------------------------




/** Commandparser structure */
typedef struct
{
  // Pointer to an array of commands
  LR_commandparser_command * cmds;
  // Pointer to the parameter buffer
  signed char * buffer;
  // Size of the parameter buffer
  unsigned int bSize;
  // Current position in the parameter buffer
  unsigned int bPos;
  // Read position in the parameter buffer
  unsigned int bRead;
  // Current position in the command words
  unsigned int cPos;
  // Size of the command array
  unsigned int cSize : 30;
  // Current mode
  unsigned int mode : 2;
} LR_commandparser;
//##############################################################################




/** Helper to define commands */
#define LR_COMMANDPARSER_CMD( STR, ID ) {.word=STR,.id=ID,.state=1}
//##############################################################################




void LR_commandparser_init( LR_commandparser * p,
   LR_commandparser_command * c, unsigned int c_size,
   signed char * b, unsigned int b_size );
//------------------------------------------------------------------------------




signed char LR_commandparser_stream( LR_commandparser * p, signed char c );
//------------------------------------------------------------------------------




signed char LR_commandparser_get( LR_commandparser * p,
    unsigned int * cmd );
//------------------------------------------------------------------------------




signed char LR_commandparser_parameter( LR_commandparser * p,
    signed char * * parm );
//------------------------------------------------------------------------------




void LR_commandparser_reset( LR_commandparser * p );
//##############################################################################




#endif //__LR_COMMANDPARSER_HEADER__

